// function *foo(x){
//     let y = 2*(yield(x+1))
//     let z = yield(y/3)
//     return x+y+z
// }

// let it = foo(5) //new Generator()  //迭代器
// console.log(it.next())
// console.log(it.next(12))//{ value: 6, done: false }
// { value: 8, done: false }
// { value: 42, done: true }

// console.log(it.next(13))
function ajax(url,callback) {
    return new Promise((resolve, reject) => {
        setTimeout(() => {
            callback(url)
            resolve()
        }, Math.random() * 1000)
    })

}
function *fetch(){
    yield ajax('URL',()=>{})  //1000ms
    yield ajax('URL2',()=>{}) //500ms
    yield ajax('URL3',()=>{}) //700ms
}

let it = fetch()
let res1 = it.next()
res1.value.then(()=>{
    let res2 = it.next()
    // console.log(res2)
   return res2.value
})
.then(()=>{
    let res3 = it.next()
})
console.log(res1);

// let res2 = it.next()
// let res3 = it.next()
